package com.kaiwu.tc.service.impl;

import com.kaiwu.tc.annotations.Autowired;
import com.kaiwu.tc.annotations.Service;
import com.kaiwu.tc.annotations.Transactional;
import com.kaiwu.tc.dao.AccountDao;
import com.kaiwu.tc.pojo.Account;
import com.kaiwu.tc.service.TransferService;

@Service("transferService")
public class TransferServiceImpl implements TransferService {

    @Autowired
    private AccountDao accountDao;

    @Transactional
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
            //int c = 1/0;
            accountDao.updateAccountByCardNo(from);

    }
}
